package class3;

import common.ListNode;
import common.ListNodeUtils;

/**
 * 删除排序链表中的重复元素
 * 1 - 2 - 2 - 3 - 3 - 4 -> 1-2-3-4
 * 1-1-1-2 -> 1-2
 */
public class Code17_deleteDuplicates {
    public static void main(String[] args) {

        ListNode head1 = ListNodeUtils.getLinked(1, 1, 1, 2, 3, 4, 5, 6);
        head1 = deleteDuplicates(head1);
        ListNodeUtils.print(head1);
    }

    public static ListNode deleteDuplicates(ListNode head) {
        if(head==null) return head;
        ListNode cur = head;
        while(cur!=null && cur.next!=null){
            if(cur.val ==cur.next.val){
                cur.next = cur.next.next;
            }else{
                cur = cur.next;
            }
        }
        return head;
    }

}
